using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Collections;
using System.Reflection;
using UMC.Web;
using UMC.Wiki.Entities;
using UMC.Web.UI;

namespace UMC.Wiki.Activities
{
    /// <summary>
    /// 邮箱账户
    /// </summary>
    public class SubjectSelfUIActivity : WebActivity
    {

        public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            var identity = this.Context.Token.Identity();

            var userId = identity.Id;

            var webr = UMC.Web.WebResource.Instance();



            var logoUrl = webr.ImageResolve(request.Url, userId.Value, "1", 4);

            var attent = DataFactory.Instance().Attention(userId.Value) ?? new Attention();


            var Discount = new UIHeader.Portrait(identity.IsAuthenticated ? logoUrl : "https://res.apiumc.com/css/images/header_image.png");

            ;
            var user = identity;
            Discount.Value(user.IsAuthenticated ? user.Alias : "请登录");
            Discount.Click(new UIClick("Account", user.IsAuthenticated ? "Self" : "Login"));

            if (user.IsAuthenticated)
            {
                var sign = DataFactory.Instance().Attention(userId.Value);
                if (sign != null)
                {

                    if (String.IsNullOrEmpty(sign.Signature))
                    {

                        Discount.Time("　");
                    }
                    else
                    {
                        Discount.Time(sign.Signature);
                    }
                }
                else
                {
                    Discount.Time("　");
                }
            }
            else
            {
                Discount.Time("　");
            }
            var color = 0x63b359;
            Discount.Gradient(color, color);
            var header = new UIHeader();
            var title = UITitle.Create();

            title.Title = "我的";
            header.AddPortrait(Discount);

            title.Style.BgColor(color);
            title.Style.Color(0xfff);

            var ui = UISection.Create(header, title);


            var uIIcon = new UIIconNameDesc(new UIIconNameDesc.Item('\uF19d', "参与项目", $"{attent.ProjectTotal ?? 0}项").Color(0x40c9c6));
            // if (user.IsAuthenticated)
            // {
            uIIcon.Button("查看", new UIClick(request.Model, "Account", new WebMeta().Put("selectIndex", 1)), 0x1890ff);
            // }
            // else
            // {
            //     uIIcon.Button("请登录", new UIClick("Account", "Login"), 0xb7babb);
            // }
            ui.Add(uIIcon);
            uIIcon = new UIIconNameDesc(new UIIconNameDesc.Item('\uF02d', "知识创作", $"{attent.SubjectTotal ?? 0}篇").Color(0x36a3f7), new UIIconNameDesc.Item('\uf0e6', "被评论", $"{attent.SubjectReplyTotal ?? 0}次").Color(0x34bfa3));
            ui.Add(uIIcon);


            ui.NewSection()
                .AddCell('\uf198', "新建文档", "采用Markdown格式编写", new Web.UIClick(request.Model, "Content", "Markdown"))
                .AddCell('\uf13b', "新建富文本文档", "采用富文本格式编写", new Web.UIClick(request.Model, "Content", "News"))
                .AddCell('\uf0c5', "抓取文档", "从粘贴板版网址中抓取文档", new Web.UIClick("Paste", new UIClick(request.Model, "CaseCMS")));

            ui.NewSection().AddCell('\uf2e1', "扫一扫", "", new Web.UIClick() { Key = "Scanning" });
            ui.NewSection()

                .AddCell('\uf013', "设置", "", Web.UIClick.Pager("System", "Setting", true, "Close"));


            ui.SendTo(this.Context);
            // response.Redirect(ui);

        }
    }
}